package com.gg.oss;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.model.PutObjectRequest;

import java.io.File;


/**
 * @author yangxinlei
 * @date 2020/4/18
 */
public class alioss {

    public static String putAliBaBaOss(String putFileName,String fileName,String bucketName){
        // Endpoint以杭州为例，其它Region请按实际情况填写。
        String endpoint = "oss-cn-hangzhou.aliyuncs.com";
        // 阿里云主账号AccessKey拥有所有API的访问权限，风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维，请登录 https://ram.console.aliyun.com 创建RAM账号。
        String accessKeyId = "LTAI4GBpwwBNQG7VRRVnA2UF";
        String accessKeySecret = "Cz9Mz42MSxmbdt6Zdz3PAQHk5otUGf";

        // 创建OSSClient实例。
        OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);

        // 创建PutObjectRequest对象。
        PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, fileName, new File(putFileName));

        // 上传文件。
        ossClient.putObject(putObjectRequest);

        // 关闭OSSClient。
        ossClient.shutdown();

        return null;
    }


    public static void main(String[] args) {
        alioss.putAliBaBaOss("C:/Users/yangxinlei/Desktop/a.jpg","yybursts.jpg","yyburst");
    }

}
